$(function () {
    console.log(0)
    if($.cookie('oneStep')){
        console.log($.cookie('oneStep'))
        var oneStep = $.cookie('oneStep')
        var obj = JSON.parse(oneStep)
        $('#password').val(obj.password)
        $('#repassword').val(obj.password)
        $('#tel').val(obj.tel)
    }



    $("#userButton").click(function () {


        var isCompany = $.cookie("isCompany");

        var password = $('#password').val();
        var repassword = $('#repassword').val();
        var tel = $('#tel').val();
        var verifyCode = $('#verifyCode').val();
        if(telchek(tel)==false){
            return false;
        }
        if(verifyCode==""||verifyCode==null){
            layerMsg("验证码不为空")
            return false;
        }
        if(password=="" || password==null){
            layerMsg("密码不为空")
            return false;
        }
        if(password.length<6){
            layerMsg('密码长度不少于6')
            return false;
        }
        if(password!=repassword){
            layerMsg('密码不一致')
            return false;
        }

        var url = '';

        if (isCompany == '1') {
            url = companyServices+"/user/reg/auth"; // 需要提交的 url
        } else {
            url = services+"/user/reg/auth"; // 需要提交的 url
        }
        $.ajax({
            type: 'post', // 提交方式 get/post
            url: url, // 需要提交的 url
            contentType:"application/json;charset=utf-8",
            xhrFields: {
				withCredentials: true
			}
            ,crossDomain: true
            ,data:JSON.stringify({
                "tel":tel		
                ,"verifyCode":verifyCode
                ,"password":password
            }),
             success: function(res) {
                // console.log(res)
                if(res.success){
                    layerMsg(res.message);
                    setTimeout(function() {
                        if (isCompany == '1') {
                            window.location.href="company/regi-persinal-info.html" ;
                        } else {
                            var oneStep = {'tel':tel,'password':password}
                            $.cookie("oneStep",JSON.stringify(oneStep))
                            window.location.href="personal/register-info.html" ;
                        }
                    },3000);
                }else{
                    layerMsg(res.message);
                }                
            },
        })

    });

    //获取验证码
    // $("#vcode").click(function(){
    //     var tel = $('#tel').val();
    //     if(telchek(tel)==false){
    //         return false;
    //     }
    //     setTime(this)
    //     $.ajax({
    //         type: 'get', // 提交方式 get/post
    //         url:services+'/user/vcode/'+tel,// 需要提交的 url
    //         contentType:"application/json;charset=utf-8",
    //         xhrFields: {
	// 			withCredentials: true
	// 		},
    //         crossDomain: true,
    //         success: function(res) {
    //             if(res.status=="00200"){
    //                 layerMsg(res.message)
    //             }else{
    //                 layerMsg("获取验证码失败!请重试")
    //             }
    //         },
    //     })
    // });
});